package org.zjx.task;

import lombok.Data;
import org.zjx.common.command.ICommand;
import org.zjx.common.entity.Address;
import org.zjx.common.entity.Quest;
import org.zjx.common.model.RouteProperties;

import java.util.List;

@Data
public abstract class Task{
    //任务标题
    protected String title;
    //任务名称
    protected String name;
    //模板
    protected List<String> templates;
    //任务类型
    protected TaskType taskType;
    //执行序号（顺序任务用）
    protected int currentIndex;
    //任务总执行次数（随机任务用）
    protected int totalReps;
    //执行次数
    protected int executeCount;
    //是否完成
    protected boolean completed;

    //领取npc坐标
    protected Address npcAddress;
    //领取npc对话
    protected List<String> dialogues;

    public Task(String title, String name, TaskType taskType) {
        this.title = title;
        this.name = name;
        this.taskType = taskType;
        this.templates = getTemplates();
        this.completed = false;
        this.currentIndex = 0;
        this.executeCount = 0;
    }


    public Quest containsQuest(List<Quest> quests){
        if (quests == null || quests.isEmpty()) return null;
        for (Quest quest:quests){
            if (quest.getName().equals(name)) return quest;
        }
        return null;
    }

    public abstract List<String> getTemplates();

    public abstract ICommand getCommand(RouteProperties routeProperties);

    void complete(Quest quest) {
        if (quest == null || completed ||  !quest.getName().equals(name)) return;
        if (taskType == TaskType.SEQUENTIAL){
            currentIndex++;
            if (currentIndex >= templates.size()){
                completed = true;
            }
        }else if (taskType == TaskType.RANDOM){
            executeCount++;
            if (executeCount >= totalReps) {
                completed = true;
            }
        }
    }
}
